from typing import *


class Solution:

    def collectTheCoins(self, coins: List[int], edges: List[List[int]]) -> int:
        n = len(coins)
        nexts = [[] for _ in range(n)]
        for a, b in edges:
            nexts[a].append(b)
            nexts[b].append(a)
        